<?php
require_once("../admin_config.inc.php");

class levels
{
    private $table = null;
    function __construct()
    {
        // create a connection to the database
        $db = connect_db();
        
        $this->table = "level";
    }
    
    function addLevel($type_name)
    {
        $id = null;
        do
        {
            $id = mt_rand();
            $check_rand = "select * from {$this->table} where level_id = $id";
            $check_res = mysql_query($check_rand);
        }while(mysql_num_rows($check_res) != 0);
        
        $typename_esc = mysql_real_escape_string($type_name);
        $quer_add = "insert into {$this->table} values('{$id}','{$typename_esc}')";
        
        $add_res = mysql_query($quer_add);
        
        return $add_res;
    }
    
    function delLevel($type_name)
    {
        $typename_esc = mysql_real_escape_string($type_name);
        $quer_del = "delete from {$this->table} where level_id = '{$typename_esc}'";
        
        $del_res = mysql_query($quer_del);
        return $del_res;
    }
    
    function editLevel($old_name,$new_name)
    {
        $oldname_esc = mysql_real_escape_string($old_name);
        $newname_esc = mysql_real_escape_string($new_name);
        $quer_edit = "update {$this->table} set level_name = '{$newname_es}' where level_name ='{$oldname_esc}'";
        
        $add_res = mysql_query($quer_edit);
        return $add_res;
    }
}
